package drinkkiosk.cards;

import java.awt.Color;

/**SendCard requests the Patron to enter their TableNumber before sending the 
 * Drink to the BartenderQueue
 * @author Charles Ritchea
 */
public class SendCard extends javax.swing.JPanel {

    /**The index of the JLabel to be changed by a NumberButton*/
    private int activeTableNumberJLabel;
    /**The TableNumber as a String*/
    private String tableNumber;

    /** Creates new form Card */
    public SendCard() {
        activeTableNumberJLabel = 0;
        tableNumber = "000";
        
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        SendNumPadJPanel = new javax.swing.JPanel();
        tableNumberButton1 = new drinkkiosk.buttons.NumberButton();
        tableNumberButton2 = new drinkkiosk.buttons.NumberButton(2);
        tableNumberButton3 = new drinkkiosk.buttons.NumberButton(3);
        tableNumberButton4 = new drinkkiosk.buttons.NumberButton(4);
        tableNumberButton5 = new drinkkiosk.buttons.NumberButton(5);
        tableNumberButton6 = new drinkkiosk.buttons.NumberButton(6);
        tableNumberButton7 = new drinkkiosk.buttons.NumberButton(7);
        tableNumberButton8 = new drinkkiosk.buttons.NumberButton(8);
        tableNumberButton9 = new drinkkiosk.buttons.NumberButton(9);
        tableNumberButton0 = new drinkkiosk.buttons.NumberButton(0);
        tableNumberClearButton1 = new drinkkiosk.buttons.ClearButton();
        enterButton1 = new drinkkiosk.buttons.EnterButton();
        tableNumberJLabel0 = new javax.swing.JLabel();
        tableNumberJLabel2 = new javax.swing.JLabel();
        tableNumberJLabel1 = new javax.swing.JLabel();
        pleaseEnterYourTableNumberJLabel = new javax.swing.JLabel();
        welcomeButton1 = new drinkkiosk.buttons.WelcomeButton();
        jLabel1 = new javax.swing.JLabel();

        setMinimumSize(new java.awt.Dimension(800, 555));

        SendNumPadJPanel.setOpaque(false);
        SendNumPadJPanel.setLayout(new java.awt.GridLayout(4, 3, 10, 10));
        SendNumPadJPanel.add(tableNumberButton1);
        SendNumPadJPanel.add(tableNumberButton2);
        SendNumPadJPanel.add(tableNumberButton3);
        SendNumPadJPanel.add(tableNumberButton4);
        SendNumPadJPanel.add(tableNumberButton5);
        SendNumPadJPanel.add(tableNumberButton6);
        SendNumPadJPanel.add(tableNumberButton7);
        SendNumPadJPanel.add(tableNumberButton8);
        SendNumPadJPanel.add(tableNumberButton9);
        SendNumPadJPanel.add(tableNumberButton0);
        SendNumPadJPanel.add(tableNumberClearButton1);
        SendNumPadJPanel.add(enterButton1);

        SendNumPadJPanel.setBounds(310, 110, 480, 400);
        jLayeredPane1.add(SendNumPadJPanel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        tableNumberJLabel0.setBackground(new java.awt.Color(255, 255, 0));
        tableNumberJLabel0.setFont(new java.awt.Font("Tahoma", 0, 48)); // NOI18N
        tableNumberJLabel0.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        tableNumberJLabel0.setText("0");
        tableNumberJLabel0.setFocusable(false);
        tableNumberJLabel0.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tableNumberJLabel0.setOpaque(true);
        tableNumberJLabel0.setBounds(360, 50, 50, 50);
        jLayeredPane1.add(tableNumberJLabel0, javax.swing.JLayeredPane.DEFAULT_LAYER);

        tableNumberJLabel2.setBackground(java.awt.Color.white);
        tableNumberJLabel2.setFont(new java.awt.Font("Tahoma", 0, 48)); // NOI18N
        tableNumberJLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        tableNumberJLabel2.setText("0");
        tableNumberJLabel2.setFocusable(false);
        tableNumberJLabel2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tableNumberJLabel2.setOpaque(true);
        tableNumberJLabel2.setBounds(690, 50, 50, 50);
        jLayeredPane1.add(tableNumberJLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        tableNumberJLabel1.setBackground(new java.awt.Color(255, 255, 255));
        tableNumberJLabel1.setFont(new java.awt.Font("Tahoma", 0, 48)); // NOI18N
        tableNumberJLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        tableNumberJLabel1.setText("0");
        tableNumberJLabel1.setFocusable(false);
        tableNumberJLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tableNumberJLabel1.setOpaque(true);
        tableNumberJLabel1.setBounds(520, 50, 50, 50);
        jLayeredPane1.add(tableNumberJLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        pleaseEnterYourTableNumberJLabel.setBackground(new java.awt.Color(255, 255, 255));
        pleaseEnterYourTableNumberJLabel.setFont(new java.awt.Font("Arial", 0, 36));
        pleaseEnterYourTableNumberJLabel.setText("Please Enter Table Number");
        pleaseEnterYourTableNumberJLabel.setOpaque(true);
        pleaseEnterYourTableNumberJLabel.setBounds(330, 10, 440, 40);
        jLayeredPane1.add(pleaseEnterYourTableNumberJLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);
        welcomeButton1.setBounds(20, 490, 143, 51);
        jLayeredPane1.add(welcomeButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/drinkkiosk/Welcome.png"))); // NOI18N
        jLabel1.setBounds(0, 0, 800, 560);
        jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 800, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 800, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 555, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 555, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    /**Cycles through the 3 JLabels changes their text to the number of the
     * NumberButton pressed. Update tableNumber to match the label text.
     * @param digit int the digit received from a NumberButtom
     */
    public void updateTableNumber(int digit) {
        switch (activeTableNumberJLabel) {
            case 0:
                tableNumberJLabel0.setText("" + digit);
                tableNumberJLabel1.setBackground(Color.yellow);
                tableNumberJLabel2.setBackground(Color.white);
                tableNumberJLabel0.setBackground(Color.white);

                tableNumber = "" + digit + tableNumber.charAt(1) + tableNumber.charAt(2);
                break;
            case 1:
                tableNumberJLabel1.setText("" + digit);
                tableNumberJLabel2.setBackground(Color.yellow);
                tableNumberJLabel1.setBackground(Color.white);
                tableNumberJLabel0.setBackground(Color.white);

                tableNumber = "" + tableNumber.charAt(0) + digit + tableNumber.charAt(2);
                break;
            case 2:
                tableNumberJLabel2.setText("" + digit);
                tableNumberJLabel0.setBackground(Color.yellow);
                tableNumberJLabel2.setBackground(Color.white);
                tableNumberJLabel1.setBackground(Color.white);
                tableNumber = "" + tableNumber.charAt(0) + tableNumber.charAt(1) + digit;
                break;
            default:
                return;
        }
        activeTableNumberJLabel = ++activeTableNumberJLabel % 3;
        return;
    }

    /**sets the tableNumber and labels to all zeroes.
     */
    public void clearTableNumber() {
        tableNumber = "000";
        tableNumberJLabel0.setBackground(Color.yellow);
        tableNumberJLabel2.setBackground(Color.white);
        tableNumberJLabel1.setBackground(Color.white);
        activeTableNumberJLabel = 0;
        tableNumberJLabel0.setText("" + 0);
        tableNumberJLabel1.setText("" + 0);
        tableNumberJLabel2.setText("" + 0);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel SendNumPadJPanel;
    private drinkkiosk.buttons.EnterButton enterButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JLabel pleaseEnterYourTableNumberJLabel;
    private drinkkiosk.buttons.NumberButton tableNumberButton0;
    private drinkkiosk.buttons.NumberButton tableNumberButton1;
    private drinkkiosk.buttons.NumberButton tableNumberButton2;
    private drinkkiosk.buttons.NumberButton tableNumberButton3;
    private drinkkiosk.buttons.NumberButton tableNumberButton4;
    private drinkkiosk.buttons.NumberButton tableNumberButton5;
    private drinkkiosk.buttons.NumberButton tableNumberButton6;
    private drinkkiosk.buttons.NumberButton tableNumberButton7;
    private drinkkiosk.buttons.NumberButton tableNumberButton8;
    private drinkkiosk.buttons.NumberButton tableNumberButton9;
    private drinkkiosk.buttons.ClearButton tableNumberClearButton1;
    private javax.swing.JLabel tableNumberJLabel0;
    private javax.swing.JLabel tableNumberJLabel1;
    private javax.swing.JLabel tableNumberJLabel2;
    private drinkkiosk.buttons.WelcomeButton welcomeButton1;
    // End of variables declaration//GEN-END:variables

    /**
     * 
     * @return
     */
    public String getTableNumber() {
        return tableNumber;
    }
}
